//
//  SaveTools.m
//  SunHouse
//
//  Created by dllo on 15/10/19.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "SaveTools.h"

@implementation SaveTools

//获取文件路径方法实现
+ (NSString *)pathWithName:(NSString *)name directory:(NSSearchPathDirectory)directory
{
    NSString *path = [NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES) firstObject];
    NSLog(@"saveToos===%@", path);
    path = [NSString stringWithFormat:@"%@/%@", path, name];
    return path;
}

//在文件内存储数据
+(BOOL)saveToFileName:(NSString *)fileName andFilePath:(NSSearchPathDirectory)directory andVaule:(NSString *)vaule
{
    NSString *string = [SaveTools pathWithName:fileName directory:directory];
    return [vaule writeToFile:string atomically:YES encoding:NSUTF8StringEncoding error:nil];
}

//从文件读取数据
+(NSString *)readFromFileName:(NSString *)fileName andFilePath:(NSSearchPathDirectory)directory
{
    NSString *string = [SaveTools pathWithName:fileName directory:directory];
    return [NSString stringWithContentsOfFile:string encoding:NSUTF8StringEncoding error:nil];
}

@end
